package com.example.mymvp02.LoginMvp;


import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.mymvp02.R;
import com.example.mymvp02.Base.BaseActivity;
import com.example.mymvp02.Utils.SystemUtils;

public class LoginActivity extends BaseActivity<LoginPresenter,ILoginContract.VP>{
    private EditText et_name,et_pwd;
    private Button btnLogin;

    @Override
    public ILoginContract.VP getContract() {
        return new ILoginContract.VP() {
            @Override
            public void requestLogin(String name, String pwd) {
                //发送获取到的信息
                //...
                mPresenter.getContract().requestLogin(name,pwd);
            }

            @Override
            public void responseLoginResult(boolean loginStatusResult) {
                //得到返回的结果 进行ui的更新
                //...
                Toast.makeText(LoginActivity.this, loginStatusResult?"登陆成功":"密码错误", Toast.LENGTH_SHORT).show();
//                SystemUtils.ActionUserOut(LoginActivity.this);//下线使用
            }
        };
    }

    @Override
    public void initContentView() {
        setContentView(R.layout.activity_login);
    }

    @Override
    public void initView() {
        et_name=findViewById(R.id.et_name);
        et_pwd=findViewById(R.id.et_pwd);
        btnLogin=findViewById(R.id.btnLogin);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        btnLogin.setOnClickListener(this);
    }

    @Override
    public void destroy() {//Activity销毁时的操作

    }

    @Override
    public LoginPresenter getPresenterInstance() {
        return new LoginPresenter();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btnLogin:
                String name=et_name.getText().toString().trim();
                String pwd=et_pwd.getText().toString().trim();
                getContract().requestLogin(name,pwd);
                break;
        }
    }
}
